#include "Common.hpp"
#include "Fifo.hpp"

int main()
{
    Sync syn;
    syn.OpenWriteOrDie();

    //1.获取key
    //cout << "I am client" << endl;
    key_t key = GetKeyOrDie();
    cout << "client key: " << ToHEX(key) << endl;
    // sleep(2);

    //2.获取共享内存块
    int shmid = GetShm(key, DEFAULT_SIZE);
    cout << "client shmid: " << shmid << endl;    
    // sleep(2);

    //3. 构建映射
    char* address = (char*)AttachShm(shmid);
    cout << "client attach done, address : " << (void*)address << endl;

    memset(address, 0, DEFAULT_SIZE);
    for (int i = 'a'; i <= 'z'; i++)
    {
        address[i - 'a'] = i;
        syn.WakeUp();
        sleep(1);
    }
    //4. 移除映射
    DetachShm(address);
    cout << "client detach done, address : " << (void*)address << endl;
    sleep(2);

    return 0;
}